#include "amentitymanager.h"
#include "base/amscene.h"
#include <stdlib.h>

AMEntityManager * AMEntityManager::get() {
    static AMEntityManager * theInstance = new AMEntityManager();
    return theInstance;
}

AMEntityManager::AMEntityManager(QObject *parent) : QObject(parent) {}

void AMEntityManager::create(const QString & entityName, MeshData * meshData) {
    AMEntity * e = new AMEntity(meshData);
    AMScene::get()->clear();
    AMScene::get()->add(e);
    m_Entities.insert(entityName, e);
    emit(entityCreated(entityName));
}

void AMEntityManager::purge(const QString & entityName) {
    AMVirtualEntity * e = m_Entities.value(entityName);
    m_Entities.remove(entityName);
    free(e);
    emit(entityPurged(entityName));
}

AMVirtualEntity * AMEntityManager::fetch(const QString & entityName) {
    return m_Entities.value(entityName);
}
